package per.ace.transactional.test;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import per.ace.transactional.pojo.User;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @program: springbootDemo
 * @description: ThreadLocal demo
 * @author: ace
 * @Date: 2020-04-08 16:56
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class ThreadLocalDemo {


    private  static ThreadLocal<String> stringThreadLocal = new ThreadLocal<String>();

    public final static User user2 = new User(23L,"alex");


    @Test
    public void test() throws InterruptedException {
        stringThreadLocal.set("alex");
        log.info("方法主线程获取的ThreadLocal值:{}", stringThreadLocal.get());
        Thread.sleep(2000L);

        new Thread(() -> log.info("新创建的线程获取的ThreadLocal值:{}", stringThreadLocal.get())).start();

        stringThreadLocal.remove();

    }

    @Test
    public void user(){
        user2.setUserId(22L);
        System.out.println(user2);
        System.out.println(user2.getUserId());

    }

}
